﻿using MicroOrm.Dapper.Repositories.SqlGenerator.Interfaces;
using MicroOrm.Dapper.Repositories.SqlGenerator.Models;
using MyServices.Models;
using MyServices.Models.Data;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Helpers;
using System.Web.Http;

namespace MyServices.Controllers
{
    public class CategoryController : ApiControllerBase
    {
        ISqlGenerator<Categories> _sqlGenerator = new SqlGenerator<Categories>(ESqlConnector.MSSQL);
        CategoryRepository repository;

        protected override void Initialize(System.Web.Http.Controllers.HttpControllerContext controllerContext)
        {
            base.Initialize(controllerContext);
            if (repository == null)
                repository = new CategoryRepository(_connection, _sqlGenerator);
        }

        [Route("api/category/test"), HttpGet]
        public string Test()
        {
            var allcate = repository.FindAll();
            return JsonConvert.SerializeObject(allcate);
        }
        [Route("api/category/add"), HttpPost]
        public bool Add(Categories model)
        {
            var task = repository.InsertAsync(model);
            return true;
        }
    }
}
